layui.define(["table", "form"], function(e) {
    var admin = layui.admin;
    var $ = layui.$,
        form = layui.form,
        table = layui.table;
    //监听搜索
    form.on('submit(LAY-info-front-search)', function(data) {
        var field = data.field;
        //执行重载
        table.reload('LAY-info-manage', {
            where: field,
            page: {
                curr: 1
            },
        });
    });
    //事件
    var active = {
        batchverify: function() {
            var checkStatus = table.checkStatus('LAY-info-manage'),
                checkData = checkStatus.data; //得到选中的数据
            if (checkData.length === 0) {
                return layer.msg('请选择数据');
            }
            layer.confirm('确定强制关闭吗？', function() {
                //执行 Ajax 后重载
                var _ids = layui.getParamValues(checkData, 'mission_id');
                layui.$.get(layui.setter.app_url + 'mission/doExpired', {
                    id: _ids.join()
                }, function(data) {
                    layer.msg(data.msg);
                    table.reload('LAY-info-manage');
                });
            });
        },
    };
    $('.layui-btn.layuiadmin-btn-info').on('click', function() {
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });
    //表格内处理     
    table.render({
            elem: "#LAY-info-manage",
            url: app_url + "mission/listDataExpired",
            cols: [
                [{
                    checkbox: true
                }, {
                    field: "mission_id",
                    title: "ID",
                    sort: !0
                }, {
                    field: "username",
                    title: "用户",
                    width: 120,
                    height: 120,
                    align: 'center',
                    templet: '#userTpl',
                }, {
                    field: "title",
                    title: "标题",
                }, {
                    field: "cat_name",
                    title: "分类",
                }, {
                    field: "money",
                    title: "任务金额",
                }, {
                    field: "content",
                    title: "任务描述",
                    height: 120,
                    templet: function(d) {
                        return htmlDecode(d.content);
                    }
                }, {
                    field: "user_partic",
                    title: "报名",
                }, {
                    field: "user_sub",
                    title: "交稿",
                }, {
                    field: "user_adopt",
                    title: "采纳",
                }, {
                    field: "money",
                    title: "奖金",
                }, {
                    field: "money_cfg",
                    title: "分配方式",
                    templet:function(d){
                        var money_cfg ={
                            1:"全额",
                            2:"等级",
                            3:"计件",
                        };
                        return money_cfg[d.money_cfg.slt_bid_mode];
                    }
                }, {
                    field: "days_expire",
                    title: "期限(天)",
                }, {
                    field: "create_time",
                    title: "创建时间",
                }, {
                    field: "update_time",
                    title: "更新时间",
                }, {
                    field: "status_txt",
                    title: "状态",
                }]
            ],
            page: !0,
            limit: 10,
            height: "full-120",
            text: "对不起，加载出现异常！"
        }), table.on("tool(LAY-info-manage)", function(e) {
            if ("edit" === e.event) {
                var _data = e.data;
                let index = layer.open({
                    type: 2,
                    title: "编辑信息",
                    content: app_url + "mission/edit?id=" + _data.mission_id,
                    maxmin: !0,
                    area: ["500px", "450px"],
                    btn: ["确定", "取消"],
                    yes: function(e, t) {
                        var l = window["layui-layer-iframe" + e],
                            r = "LAY-info-front-submit",
                            n = t.find("iframe").contents().find("#" + r);
                        l.layui.form.on("submit(" + r + ")", function(t) {
                            $.put(layui.setter.app_url + 'mission/update?id=' + _data.mission_id, t.field, function(data, textStatus, xhr) {
                                if (data.status == 1) {
                                    table.reload("LAY-info-manage"), layer.close(e)
                                }
                                layui.layer.msg(data.msg);
                            }, 'json');
                        }), n.trigger("click")
                    },
                    success: function(e, t) {}
                });
            }
        }),
        table.on('sort(LAY-info-manage)', function(obj) {
            table.reload('LAY-info-manage', {
                initSort: obj,
                page: {
                    curr: 1
                },
                where: {
                    sort: obj.field,
                    order: obj.type
                }
            });
        });
    e("missionexpired", {})
});